﻿using Rex.Assignment.Common;
using System;
using System.Linq;
using System.Linq.Expressions;

namespace Rex.Assignment.Domain.Repository
{
    public partial interface IBaseRepository<T> where T : class, new()
    {
        /// <summary>
        /// 新增数据
        /// </summary>
        /// <param name="t">数据对象</param>
        int Add(T t);

        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="t">数据对象</param>
        int Update(T t);

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="t">数据对象</param>
        int Delete(T t);

        /// <summary>
        /// 查询所有数据
        /// </summary>
        /// <returns></returns>
        IQueryable<T> GetModelsAll();

        /// <summary>
        /// 根据条件查询
        /// </summary>
        /// <typeparam name="type">排序的字段类型</typeparam>
        /// <param name="isAsc">是否升序</param>
        /// <param name="orderByExpression">排序表达式</param>
        /// <param name="whereExpression">条件表达式</param>
        /// <returns></returns>
        IQueryable<T> GetModels<type>(bool isAsc, Expression<Func<T, type>> orderByExpression, Expression<Func<T, bool>> whereExpression);

        /// <summary>
        /// 分页查询数据信息
        /// </summary>
        /// <typeparam name="type">排序的字段类型</typeparam>
        /// <param name="page">当前页</param>
        /// <param name="limit">查询的数量</param>
        /// <param name="isAsc">是否升序</param>
        /// <param name="orderByExpression">排序表达式</param>
        /// <param name="whereExpression">条件表达式</param>
        /// <returns></returns>
        PageObject<T> GetModelsByPage<type>(int page, int limit, bool isAsc, Expression<Func<T, type>> orderByExpression, Expression<Func<T, bool>> whereExpression);

        /// <summary>
        /// 根据主键ID查询
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <returns></returns>
        T GetModelsById(object id);

    }
}
